﻿using System;
using Microsoft.AspNetCore.Mvc;
using MRMDS.Module;
using MRMDS.Module.Response;
using MRMDS.Utils;

namespace Demo.Controllers
{
    [ApiController]
    [Route("Viewer")]
    public class ViewerRelateController : ControllerBase
    {
        private readonly GlobalManager global;

        public ViewerRelateController()
        {
            global = GlobalManager.Instance;
        }


        [Route("WatchSet")]
        [HttpPut]
        public DefaultResponse SetWatchSet([FromQuery] string uuid, [FromBody] string[] watchSet)
        {
            if (!global.UUID2Viewer.TryGetValue(uuid, out Viewer? instance))
            {
                Logger.Write($"Watset Change Fail (0).(uuid:{uuid})");
                return DefaultResponse.FailUUIDNullRefer;
            }
            instance.WatchSet = watchSet;
            Logger.Write($"Watset Change Success.(uuid:{uuid})");
            return DefaultResponse.SuccessNullMessage;
        }

        [Route("WatchSet")]
        [HttpGet]
        public string[]? GetWatchSet([FromQuery] string uuid)
        {
            if (!global.UUID2Viewer.TryGetValue(uuid, out Viewer? instance))
            {
                Logger.Write($"Watset Get Fail (0).(uuid:{uuid})");
                return null;
            }
            return instance.WatchSet;
        }

        [Route("CurrentStates")]
        [HttpGet]
        public ActorStateResponse[]? GetStatesbyWatchSet([FromQuery] string uuid)
        {
            if (!global.UUID2Viewer.TryGetValue(uuid, out Viewer? instance))
            {
                Logger.Write($"States Get Fail (0).(uuid:{uuid})");
                return null;
            }
            return instance.GetStatesByWatchSet();
        }
    }

}